<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<style>
 td{border: 1px solid red;}
</style>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
				<input type="hidden" th:value="${contest.id}" name="contestId"/>
				</form>
				<h1 id="title" align="center">[[${contest.title}]]</h1>
				<h3 align="center">开始时间：[[${#dates.format(contest.startTime,'yyyy-MM-dd HH:mm:ss')}]]</h3>
				<span class="text-muted">
                <th:block th:include="common :: countdown" />
                </span>
				<h3 align="center">结束时间：[[${#dates.format(contest.endTime,'yyyy-MM-dd HH:mm:ss')}]]</h3>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" ></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
    var cpnum=[[${cpnum}]];
    var maxtime=0;
    $(function() {    	
        var options = {
                url: ctx + "acm/attend/list",
                modalName: "排名成绩",
    			search: false,
    	        showExport: false,
    	        showSearch:false,
    	        showRefresh: false, 
    	        showToggle:false,
    	        showColumns:false,
    	        sortName: "solved",    // 排序列名称
                sortOrder: "desc",
                pageSize: 50,
                //striped: true,
                //theadClasses: "thead-dark",
                classes:"table table-bordered table-striped table-sm table-dark",
                columns: [
    			{
    				field : 'id',
    				title : '名次',
    				formatter: function(value, row, index) {
    					return index+1;
    				},
    				cellStyle:function(value,row,index){//应该按人数的比例设定名次段
    					if(index < 10) return {css:{"background-color":"gold!important","text-align": "center"}}
    					else return {css:{"background-color":"#fff!important","text-align": "center"}}  					
    				}
    			},
    			{
    				field : 'uid', 
    				title : '用户'
    			},
    			{
    				field : 'solved', 
    				title : 'AC',
    				formatter: function(value, row, index) {
    					if(!value) return 0;
    					else return value;
    				}
    			},
    			{
    				field : 'score', 
    				title : 'score'
    			},
    			{
    				field : 'penalty', 
    				title : '罚分',
    				formatter: function(value, row, index) {
    					return fmtTime(value);
    				}
    			},
    			{
    				field : 'aTime', 
    				title : 'A',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.aWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.aWrongsubmits,index);  					
    				}
    			},
       			{
    				field : 'bTime', 
    				title : 'B',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.bWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.bWrongsubmits,index);  					
    				}
    			},
       			{
    				field : 'cTime', 
    				title : 'C',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.cWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.cWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'dTime', 
    				title : 'D',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.dWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.dWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'eTime', 
    				title : 'E',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.eWrongsubmits);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.eWrongsubmits,index);  					
    				}
    			},
    			
    			{
    				field : 'fTime', 
    				title : 'F',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.fWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.fWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'gTime', 
    				title : 'G',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.gWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.gWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'hTime', 
    				title : 'H',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.hWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.hWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'iTime', 
    				title : 'I',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.iWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.iWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'jTime', 
    				title : 'J',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.jWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.jWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'kTime', 
    				title : 'K',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.kWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.kWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'lTime', 
    				title : 'L',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.lWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.lWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'mTime', 
    				title : 'M',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.mWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.mWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'nTime', 
    				title : 'N',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.nWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.nWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'oTime', 
    				title : 'O',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.oWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.oWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'pTime', 
    				title : 'P',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.pWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.pWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'qTime', 
    				title : 'Q',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.qWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.qWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'rTime', 
    				title : 'R',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.rWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.rWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'sTime', 
    				title : 'S',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.sWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.sWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'tTime', 
    				title : 'T',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.tWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.tWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'uTime', 
    				title : 'U',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.uWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.uWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'vTime', 
    				title : 'V',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.vWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.vWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'wTime', 
    				title : 'W',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.wWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.wWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'xTime', 
    				title : 'X',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.xWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.xWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'yTime', 
    				title : 'Y',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.yWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.yWrongsubmits,index);  					
    				}
    			},
    			{
    				field : 'zTime', 
    				title : 'Z',
    				formatter: function(value, row, index) {
    					return iofmt(value,row.zWrongsubmits,index);
    				},
    				cellStyle:function(value,row,index){
    					return iocellcss(value,row.zWrongsubmits,index);  					
    				}
    			}
    			]
            };
            $.table.init(options);
            maxtime=[[${maxtime}]];
            setTimeout(refreshstatus, 1000);

        });
function refreshstatus(){	
	$.table.refresh();
	for(var i=cpnum;i>0 && i<26;i++)
	{
		$.table.hideColumn(String.fromCharCode(97+i)+'Time');
	}
	if(maxtime>0) {
		maxtime-=10;
		setTimeout(refreshstatus, 10000);
	}else $("#title").html([[${contest.title}]]+"已结束");
}
function iofmt(value,smt){
	if(value){
		var v=fmtTime(value);
		if(smt && smt>0)
			return v+"<br>(-"+smt+")";
		else if(value>0)  return v;
	}else {
		if(smt && smt>0)
			return "<br>(-"+smt+")";
		else return "";
	}
}
function iocellcss(value,smt,index){
	if(!value && smt && smt>0)//只有错误提交
		return {css:{"background-color":"#ee9090!important","text-align": "center"}}
	else if(value && value>0) //存在AC
		return {css:{"background-color":"#90ee90!important","text-align": "center"}}
	else if(index%2==0) return {css:{"background-color":"#f7f7f7!important"}}
	else if(index%2==1) return {css:{"background-color":"#fff!important"}}
}
function fmtTime(value){
	if(!value)return "00:00:00";
	
	var sec=value%60;
	var s=parseInt(value/60);
	var min=s%60;
	var hour=parseInt(s/60);
	var nowTime="";
	
	if(hour<10) {
		if(hour==0) nowTime="00";
		else nowTime="0"+hour;
	}else nowTime=hour;

	if(min<10) {
		nowTime=nowTime+":0"+min;
	}else {nowTime=nowTime+":"+min;}
	
	if(sec<10) {
		nowTime=nowTime+":0"+sec;
	}else {nowTime=nowTime+":"+sec;}
	
	return nowTime;
}
    </script>
<script th:src="@{/assets/js/timecountdown.js}"></script>
    <script>
    $(function(){
    	var maxtime=[[${maxtime}]];
    	if(maxtime==0) {
    		document.getElementById("h4").innerHTML="已";
            document.getElementById("i4").innerHTML="结";
            document.getElementById("s4").innerHTML="束";
    	}
    	else if(maxtime==-1) {
    		document.getElementById("h4").innerHTML="未";
            document.getElementById("i4").innerHTML="开";
            document.getElementById("s4").innerHTML="始";
    	}
    	else
    	xcsoft.countdown3('[[${now0}]]','[[${#dates.format(contest.endReg,"yyyy-MM-dd HH:mm:ss")}]]',function (time) {
            document.getElementById("h4").innerHTML=time.hourZero
            document.getElementById("i4").innerHTML=time.minuteZero
            document.getElementById("s4").innerHTML=time.secondZero
        });
    })
    </script>       
</body>
</html>